package nc.ui.med.pub.query;

import java.util.ArrayList;
import java.util.HashSet;

import nc.ui.querytemplate.filter.IFilter;
import nc.vo.pub.query.ConditionVO;

public class GspSqlProcessor implements ISqlProcessor {

	private ArrayList<MedDefaultFilter> listconvo;

	private HashSet<IFilter> hsfilter;

	public String processWhere(MedDefaultFilter filter, String basicWhere) {
		if (filter != null && hsfilter != null && !hsfilter.contains(filter)
				&& listconvo != null && filter.getOperator() != null
				&& filter.getFieldValue() != null
				&& filter.getFieldValue().getFieldValues() != null
				&& filter.getFieldValue().getFieldValues().size() > 0) {
			listconvo.add(filter);
			hsfilter.add(filter);
		}
		return basicWhere;
	}

	public ConditionVO[] getConditionVO(QueryConditionBaseDLG dlg) {
		listconvo = new ArrayList<MedDefaultFilter>();
		hsfilter = new HashSet<IFilter>();

		dlg.getWhereSQLNotPower();

		if (listconvo == null || listconvo.size() <= 0)
			return null;
		ConditionVO[] convos = new ConditionVO[listconvo.size()];
		for (int i = 0; i < listconvo.size(); i++) {
			convos[i] = QueryDlgUtil.convert2ConditionVO(listconvo.get(i));
		}
		listconvo = null;
		hsfilter = null;
		return convos;
	}

	public void clearConditionVOData() {
		listconvo.clear();
	}
}
